var wavFileInfo = require('wav-file-info');
var os = require('os');
var fs = require('fs');

class WavInfo{
    constructor(){

    }

    getWavInfo(name,cb){
        if (name){
            var wi = [];
            var file = name;
            if (os.platform() == 'darwin'){
                var tmp = os.homedir() + name.split(':')[1];
                file = tmp.split('\\').join('/');
            }
            try{
                wavFileInfo.infoByFilename(file,function(err, info){
                    if (err) return cb(null,null);
                    if (info.header.num_channels == 1){
                        wi.push('Mono');
                    }
                    else{
                        wi.push('Stereo');
                    }
                    wi.push(info.duration);
                    wi.push(info.header.sample_rate);
                    return cb(null,wi);
                });
            }catch(err){
                return cb(null,null);
            }
        }
        else{
            return cb(null,null);
        }
    }
}

module.exports = WavInfo;